<?php
class NoidungsController extends AppController {

	var $name = 'Noidungs';

	function index() {
		$this->Noidung->recursive = 0;
		$this->set('noidungs', $this->paginate());
        $idnhanvien=$this->Session->read('cur_manv');
        $this->set(compact('idnhanvien'));
	}

	function view($id = null) {
		if (!$id) {
			$this->Session->setFlash(__('Invalid noidung', true));
			$this->redirect(array('action' => 'index'));
		}
		$this->set('noidung', $this->Noidung->read(null, $id));
	}

	function add() {
		if (!empty($this->data)) {
			$this->Noidung->create();
            $this->data ['Noidung'] ['nhanvien_id'] =$this->Session->read('cur_manv');
            $this->data ['Noidung'] ['ngaytao'] =date('Y-m-d H:m:s');
		
			if ($this->Noidung->save($this->data)) {
				$this->Session->setFlash(__('Bài viết đã được tạo', true), 
                        'default', array('class' => 'success'));              
				$this->redirect(array('controller'=>'z2forums','action' => 'index'));
			} else {
				$this->Session->setFlash(__('The noidung could not be saved. Please, try again.', true));
			}
		}
		$nhanviens = $this->Noidung->Nhanvien->find('list');
		$this->set(compact('nhanviens'));
	}

	function edit($id = null) {
		if (!$id && empty($this->data)) {
			$this->Session->setFlash(__('Invalid noidung', true));
			$this->redirect(array('action' => 'index'));
		}
		if (!empty($this->data)) {
			if ($this->Noidung->save($this->data)) {
				$this->Session->setFlash(__('The noidung has been saved', true));
				$this->redirect(array('action' => 'index'));
			} else {
				$this->Session->setFlash(__('The noidung could not be saved. Please, try again.', true));
			}
		}
		if (empty($this->data)) {
			$this->data = $this->Noidung->read(null, $id);
		}
		$nhanviens = $this->Noidung->Nhanvien->find('list');
		$this->set(compact('nhanviens'));
	}

	function delete($id = null) {
		if (!$id) {
			$this->Session->setFlash(__('Invalid id for noidung', true));
			$this->redirect(array('controller'=>'z2forums','action'=>'index'));
		}
		if ($this->Noidung->delete($id)) {
			$this->Session->setFlash(__('Noidung deleted', true));
			$this->redirect(array('controller'=>'z2forums','action'=>'index'));
		}
		$this->Session->setFlash(__('Noidung was not deleted', true));
		$this->redirect(array('controller'=>'z2forums','action'=>'index'));
	}
}
